load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@io_bazel_rules_go//go:def.bzl", "go_cross_binary", "nogo")
load("//:def.bzl", "gazelle", "gazelle_binary")

# gazelle:prefix github.com/bazelbuild/bazel-gazelle
# gazelle:exclude vendor
# gazelle:exclude third_party
# gazelle:exclude .bazelci
# gazelle:exclude .bcr
# gazelle:exclude .idea
# gazelle:exclude .ijwb
# gazelle:exclude .github
# gazelle:exclude .vscode
# gazelle:exclude internal/module/testdata
# gazelle:go_naming_convention import_alias
gazelle(
    name = "gazelle",
    command = "fix",
    gazelle = ":gazelle_local",
)

# gazelle_ci is called from CI to verify the repo is up-to-date, see: .bazelci/presubmit.yml
gazelle(
    name = "gazelle_ci",
    command = "fix",
    extra_args = ["--mode=diff"],
    gazelle = ":gazelle_local",
)

gazelle_binary(
    name = "gazelle_local",
    languages = [
        "//language/proto",
        "//language/go",
        "//internal/language/test_filegroup",
        "@bazel_skylib_gazelle_plugin//bzl",
    ],
)

go_cross_binary(
    name = "gazelle_local_go1.22",
    sdk_version = "1.22",
    target = ":gazelle_local",
)

nogo(
    name = "nogo",
    vet = True,
    visibility = ["//visibility:public"],
    deps = ["@org_golang_x_tools//go/analysis/passes/copylock"],
)

exports_files(
    [
        "WORKSPACE",
        "def.bzl",
        "extend.md",
        "extensions.bzl",
        "extensions.md",
        "reference.md",
    ],
    visibility = ["//:__subpackages__"],
)

filegroup(
    name = "all_files",
    testonly = True,
    # keep
    srcs = glob(["vendor/**"]) + [
        ".bazelrc",
        ".gitignore",
        "AUTHORS",
        "BUILD.bazel",
        "CODEOWNERS",
        "CONTRIBUTING.md",
        "CONTRIBUTORS",
        "Design.md",
        "LICENSE",
        "README.md",
        "WORKSPACE",
        "def.bzl",
        "deps.bzl",
        "go.mod",
        "go.sum",
        "//cmd:all_files",
        "//config:all_files",
        "//flag:all_files",
        "//internal:all_files",
        "//label:all_files",
        "//language:all_files",
        "//merger:all_files",
        "//pathtools:all_files",
        "//repo:all_files",
        "//resolve:all_files",
        "//rule:all_files",
        "//testtools:all_files",
        "//tools:all_files",
        "//walk:all_files",
    ],
    visibility = ["//visibility:public"],
)

bzl_library(
    name = "def",
    srcs = ["def.bzl"],
    visibility = ["//visibility:public"],
    deps = [
        "//internal:gazelle_binary",
        "//internal:go_repository",
        "//internal:overlay_repository",
        "//internal/generationtest",
        "@bazel_gazelle_go_repository_config//:go_env.bzl",
        "@bazel_gazelle_is_bazel_module//:defs",
        "@bazel_skylib//lib:shell",
        "@rules_shell//shell:rules_bzl",
    ],
)

bzl_library(
    name = "deps",
    srcs = ["deps.bzl"],
    visibility = ["//visibility:public"],
    deps = [
        "//internal:go_repository",
        "//internal:go_repository_cache",
        "//internal:go_repository_config",
        "//internal:go_repository_tools",
        "//internal:is_bazel_module",
        "@bazel_tools//tools/build_defs/repo:git.bzl",
    ],
)

bzl_library(
    name = "extensions",
    srcs = ["extensions.bzl"],
    visibility = ["//visibility:public"],
    deps = ["//internal/bzlmod:go_deps"],
)

bzl_library(
    name = "go_tools",
    srcs = ["go_tools.bzl"],
    visibility = ["//visibility:public"],
    deps = ["@bazel_gazelle_go_repository_config//:go_tools.bzl"],
)
